package com.nbsaas.boot.app.rest.convert;

import com.nbsaas.boot.app.api.domain.response.AppMenuResponse;
import com.nbsaas.boot.app.data.entity.AppMenu;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;

/**
 * 菜单-实体对象转化成响应对象
 */

public class AppMenuResponseConvert implements Converter<AppMenuResponse, AppMenu> {

    @Override
    public AppMenuResponse convert(AppMenu source) {
        AppMenuResponse result = new AppMenuResponse();
        BeanDataUtils.copyProperties(source, result);
        if (source.getParent() != null) {
            result.setParent(source.getParent().getId());
        }
        if (source.getApp() != null) {
            result.setApp(source.getApp().getId());
        }

        try {
            if (source.getApp() != null) {
                result.setAppName(source.getApp().getName());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getParent() != null) {
                result.setParentName(source.getParent().getName());
            }
        } catch (Exception ignored) {
        }

        return result;
    }

}

